package zhaoq_hero.superapp;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.graphics.Palette;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

public class PalrtteActivity extends AppCompatActivity implements Palette.PaletteAsyncListener {

    private ImageView imageView;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_palrtte);

        imageView = (ImageView) findViewById(R.id.img_view);
        textView = (TextView) findViewById(R.id.txt_view);

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.logo_1);

        imageView.setImageBitmap(bitmap);

        /**
         * 无参的为 同步方法  会阻塞线程
         * 使用有参的  准备处理bitmap
         */
        Palette.from(bitmap).generate(this);  //处理图片
    }

    /**
     * 调色板处理  完成的回调
     * @param palette
     */
    @Override
    public void onGenerated(Palette palette) {

        //获取 用于覆盖在图片上的主题颜色
        int darkMutedColor = palette.getDarkMutedColor(Color.WHITE);

        int red = Color.red(darkMutedColor);
        int green = Color.green(darkMutedColor);
        int blue = Color.blue(darkMutedColor);

        darkMutedColor = Color.argb(0X99,red,green,blue);

        textView.setBackgroundColor(darkMutedColor);

    }

}
